<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
          // 闭包应用-计算打车价格 
        // 打车起步价13(3公里内),  之后每多一公里增加 5块钱.  用户输入公里数就可以计算打车价格
        // 如果有拥堵情况,总价格多收取10块钱拥堵费
       var car = (function(){
            var start = 13;
            var total = 0;
            return {
                price: function(i){
                    if(i <= 3){
                        return  total = start;
                    }else{
                        return total = start + 5*(i-3) ;
                    }
                },
                yd : function(flag){
                    return flag?  total+10: total;

               }
            }

        })();
        console.log(car.price(10));
        console.log(car.yd(true));


    </script>
</body>
</html>